package com.sxu.demo;

import java.time.LocalTime;
import java.util.Timer;
import java.util.TimerTask;

/**
 * Timer
 */
public class Test6 {
    public static void main(String[] args) {
        Timer timer = new Timer();
        TimerTask task1 = new TimerTask() {
            @Override
            public void run() {
                System.out.println("任务1开始：" + LocalTime.now().toString());
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        };
        TimerTask task2 = new TimerTask() {
            @Override
            public void run() {
                System.out.println("任务2开始：" + LocalTime.now().toString());
            }
        };
        System.out.println("start......" + LocalTime.now().toString());
        timer.schedule(task1, 2000);
        timer.schedule(task2, 2000);
    }
}
